/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package diepafi;

import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.swing.JOptionPane;
import model.Artist;
import model.MusicGerne;
import programm.DBmanager;

/**
 *
 * @author Παναγιώτης
 */
public class CreateArtistGUI extends javax.swing.JFrame {
    int oldId; //μεταβλητή για το "κράτημα" κωδικού προς επεξεργασία καλλιτέχνη
    Artist editArtist = new Artist(); //κρατά τον προς επεξεργασία καλλιτέχνη
    private static EntityManager em; // O entity manager   
    private KallitexnesGUI kg = new KallitexnesGUI();
    
    /**
     * Creates new form CreateArtistGUI
     */
    public CreateArtistGUI() {
        
        DBmanager dbm = new DBmanager(); 
        CreateArtistGUI.em=dbm.getEm();
        
        initComponents();
    }
    
    //κατασκευαστής με παράμετρο για να θυμάται το γονικό παράθυρο
    public CreateArtistGUI(KallitexnesGUI kg) {
        
        DBmanager dbm = new DBmanager(); 
        CreateArtistGUI.em=dbm.getEm();
        
        this.kg=kg;
        initComponents();
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jTextFieldSurname = new javax.swing.JTextField();
        jTextFieldArtistic = new javax.swing.JTextField();
        jTextFieldBirthPlace = new javax.swing.JTextField();
        jComboBoxSex = new javax.swing.JComboBox();
        jComboBoxGerne = new javax.swing.JComboBox();
        jTextFieldDay = new javax.swing.JTextField();
        jTextFieldMonth = new javax.swing.JTextField();
        jTextFieldYear = new javax.swing.JTextField();
        jButtonSave = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση καλλιτέχνη");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));

        jPanel2.setBackground(new java.awt.Color(51, 51, 51));
        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(240, 240, 240));
        jLabel1.setText("Όνομα:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(240, 240, 240));
        jLabel2.setText("Επώνυμο:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(240, 240, 240));
        jLabel3.setText("Καλλιτεχνικό:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(240, 240, 240));
        jLabel4.setText("Φύλο:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(240, 240, 240));
        jLabel5.setText("Ημ. Γέννησης:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(240, 240, 240));
        jLabel6.setText("Τόπος Γέννησης:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(240, 240, 240));
        jLabel7.setText("Μουσικό είδος:");

        jTextFieldName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldName.setNextFocusableComponent(jTextFieldSurname);

        jTextFieldSurname.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldSurname.setNextFocusableComponent(jTextFieldArtistic);

        jTextFieldArtistic.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldArtistic.setNextFocusableComponent(jComboBoxSex);

        jTextFieldBirthPlace.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldBirthPlace.setNextFocusableComponent(jComboBoxGerne);

        jComboBoxSex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Άνδρας", "Γυναίκα" }));
        jComboBoxSex.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jComboBoxSex.setNextFocusableComponent(jTextFieldDay);

        jComboBoxGerne.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Rock", "World", "Pop", "Jazz", "Metal" }));
        jComboBoxGerne.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jComboBoxGerne.setNextFocusableComponent(jButtonSave);

        jTextFieldDay.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldDay.setText("ΗΗ");
        jTextFieldDay.setNextFocusableComponent(jTextFieldMonth);
        jTextFieldDay.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldDayFocusGained(evt);
            }
        });

        jTextFieldMonth.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldMonth.setText("ΜΜ");
        jTextFieldMonth.setNextFocusableComponent(jTextFieldYear);
        jTextFieldMonth.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldMonthFocusGained(evt);
            }
        });

        jTextFieldYear.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldYear.setText("ΕΕΕΕ");
        jTextFieldYear.setNextFocusableComponent(jTextFieldBirthPlace);
        jTextFieldYear.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldYearFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(99, 99, 99)
                        .addComponent(jTextFieldName))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(59, 59, 59)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldSurname)
                            .addComponent(jTextFieldArtistic)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jComboBoxSex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addGap(35, 35, 35)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldBirthPlace)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxGerne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jTextFieldDay, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldYear, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 358, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldArtistic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxSex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldBirthPlace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxGerne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonSave.setBackground(new java.awt.Color(0, 0, 0));
        jButtonSave.setForeground(new java.awt.Color(240, 240, 240));
        jButtonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/floppyNeg.png"))); // NOI18N
        jButtonSave.setText("Αποθήκευση");
        jButtonSave.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButtonSave.setNextFocusableComponent(jButtonCancel);
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveActionPerformed(evt);
            }
        });

        jButtonCancel.setBackground(new java.awt.Color(0, 0, 0));
        jButtonCancel.setForeground(new java.awt.Color(240, 240, 240));
        jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.gif"))); // NOI18N
        jButtonCancel.setText("Άκυρο");
        jButtonCancel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButtonCancel.setNextFocusableComponent(jTextFieldName);
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButtonSave)
                        .addGap(505, 505, 505)
                        .addComponent(jButtonCancel)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSave)
                    .addComponent(jButtonCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        kg.setEnabled(true); //επανενεργοποιεί το γονικό παράθυρο
        this.dispose();
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
       //τροποποίηση του πίνακα με τα νέα δεδομένα
        //δημιουργία ενός καλλιτέχνη με τιμές των πεδίων του τα περιεχόμενα της φόρμας
        Artist newArtist = new Artist();
        String name = jTextFieldName.getText();
        String surname = jTextFieldSurname.getText();
        String artistic = jTextFieldArtistic.getText();
        String sex = jComboBoxSex.getSelectedItem().toString();
        
//έλεγχος της εισαχθήσας ημερομηνίας και αρχικοποίηση τιμών σε περίπτωση λάθους
        int day, month, year;
        try {
            day = Integer.parseInt(jTextFieldDay.getText());
            if (day>31 || day<1) day=1;
            month = Integer.parseInt(jTextFieldMonth.getText())-1;
            if (month>11 || month<0) month=1;
            year = Integer.parseInt(jTextFieldYear.getText());
            if (year>2015 || year<1500) year=1985; //αν έχει δοθεί υπερβολικά μεγάλο ή μικρό έτος, αυτό αρχικοποιείται σε μια τιμή
        } catch (Exception ie) {
            JOptionPane.showMessageDialog(this , "Λάθος ημερομηνία!", "Ημερομηνία Γέννησης", JOptionPane.ERROR_MESSAGE);
            return;           
        }
            
        Date birth = new Timestamp(year-1900, month, day, 0,0,0,0);
        String birthPlace = jTextFieldBirthPlace.getText();
        String gerne = jComboBoxGerne.getSelectedItem().toString();
        
        //έλεγχος εγκυρότητας δεδομένων
        if(name.length() > 20 || name.length()<1){
            JOptionPane.showMessageDialog(this , "Όχι κενό και μέχρι 20 χαρακτήρες!", "Όνομα", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        if(surname.length() > 20 || surname.length()<1){
            JOptionPane.showMessageDialog(this , "Όχι κενό και μέχρι 20 χαρακτήρες!", "Επώνυμο", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(artistic.length() > 20 || artistic.length()<1){
            JOptionPane.showMessageDialog(this , "Όχι κενό και μέχρι 20 χαρακτήρες!\nΑν δεν έχει καλλιτεχνικό γράψε ξανά το επώνυμό του", "Καλλιτεχνικό Όνομα", JOptionPane.ERROR_MESSAGE);
            return;
        }        
        if(birthPlace.length() > 30){
            JOptionPane.showMessageDialog(this , "Μέχρι 60 χαρακτήρες!", "Τόπος γέννησης", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        //εισαγωγή
        newArtist.setFirstName(name);
        newArtist.setLastName(surname);
        newArtist.setArtisticName(artistic);
        newArtist.setSex(sex);
        newArtist.setBirthDay(birth);
        newArtist.setBirthPlace(birthPlace);
        
        //Αντλούμε -και εισάγουμε- το μουσικό είδος που υπηρετεί ο καλλιτέχνης        
        Query q2 = em.createQuery("SELECT m FROM MusicGerne m WHERE m.genreName=\""+gerne+"\"", MusicGerne.class);
        MusicGerne mGenre=(MusicGerne) q2.getSingleResult();
        newArtist.setGenreId(mGenre);
        
        //αν ο τίτλος του παραθύρου είναι "Δημιουργία" αποθηκεύουμε το νέο καλλιτέχνη στη βάση
        switch (this.getTitle()) {
            case "Δημιουργία":
                try {
                    em.getTransaction().begin();
                    em.persist(newArtist);
                    em.getTransaction().commit();
                    kg.addToList(newArtist); //περνάμε τον τραγουδιστή στο γονικό παράθυρο για να προστεθεί στον πίνακα
                } catch (Exception e) {
                    em.getTransaction().rollback();
                }
                //αλλιώς, αν είναι "Επεξεργασία" αναζητούμε την εγγραφή στον πίνακα
                //και τροποποιούμε να πεδία της
                break;
            case "Επεξεργασία":
                Artist editedArtist=em.find(Artist.class, oldId); //στην oldId έχουμε αποθηκεύσει την id του επιλεγμένου καλλιτέχνη
                em.getTransaction().begin();
                editedArtist.setFirstName(name);
                editedArtist.setLastName(surname);
                editedArtist.setArtisticName(artistic);
                editedArtist.setSex(sex);
                editedArtist.setBirthDay(birth);
                editedArtist.setBirthPlace(birthPlace);
                editedArtist.setGenreId(mGenre);
                em.getTransaction().commit();
                kg.setListFields(editedArtist); //και περνάμε στην γονική φόρμα τα νέα στοιχεία του
                break;
        }
        
        kg.setEnabled(true);
        this.dispose();


    }//GEN-LAST:event_jButtonSaveActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        kg.setEnabled(true); //κλείνοντας ενεργοποιούμε την προηγούμενη φόρμα
    }//GEN-LAST:event_formWindowClosing

    private void jTextFieldMonthFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldMonthFocusGained
        jTextFieldMonth.selectAll();
    }//GEN-LAST:event_jTextFieldMonthFocusGained

    private void jTextFieldYearFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldYearFocusGained
        jTextFieldYear.selectAll();
    }//GEN-LAST:event_jTextFieldYearFocusGained

    private void jTextFieldDayFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldDayFocusGained
        jTextFieldDay.selectAll();
    }//GEN-LAST:event_jTextFieldDayFocusGained

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CreateArtistGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CreateArtistGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CreateArtistGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CreateArtistGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new CreateArtistGUI().setVisible(true);
        });
       
    }
    
    //μέθοδος για το "γέμισμα" των πεδίων της φόρμας με τα στοιχεία του επιλεγμένου καλλιτέχνη
    public void setFields() {
        if(this.getTitle().equals("Επεξεργασία")) {
            jTextFieldName.setText(editArtist.getFirstName());
            jTextFieldSurname.setText(editArtist.getLastName());
            jTextFieldArtistic.setText(editArtist.getArtisticName());
            jTextFieldBirthPlace.setText(editArtist.getBirthPlace());
            jComboBoxSex.setSelectedItem(editArtist.getSex());
            jComboBoxGerne.setSelectedItem(editArtist.getGenreId().getGenreName());
            Date date = editArtist.getBirthDay();
            int day= date.getDate();
            int month=1+date.getMonth();
            int year=1900+date.getYear();
            jTextFieldDay.setText(Integer.toString(day));
            jTextFieldMonth.setText(Integer.toString(month));
            jTextFieldYear.setText(Integer.toString(year));
            oldId=editArtist.getArtistId();
            
        }
        
    }
    //ορίζει τον προς επεξεργασία καλλιτέχνη
    public void setEditArtist(Artist editArtist) {
        this.editArtist=editArtist;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JComboBox jComboBoxGerne;
    private javax.swing.JComboBox jComboBoxSex;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextFieldArtistic;
    private javax.swing.JTextField jTextFieldBirthPlace;
    private javax.swing.JTextField jTextFieldDay;
    private javax.swing.JTextField jTextFieldMonth;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldSurname;
    private javax.swing.JTextField jTextFieldYear;
    // End of variables declaration//GEN-END:variables
}
